﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Diagnostics;

namespace Student
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        //皮肤控件
        private void cmb_Style_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cmb_Style.Text=="金属黑")
            {
                this.skinEngine1.Active = true;//启动皮肤控件
                this.skinEngine1.SkinFile = "skin/CalmnessColor1.ssk";//皮肤文件
            }
            else if(this.cmb_Style.Text=="宝石蓝")
            {
                this.skinEngine1.Active = true;
                this.skinEngine1.SkinFile = "skin/EmeraldColor1.ssk";
            }
            else
            {
                this.skinEngine1.Active = false;
            }
        }

        //登录
        private void btn_Login_Click(object sender, EventArgs e)
        {
            //获取用户输入的账号
            string userName = this.txt_UserName.Text.Trim();
            //获取用户输入的密码
            string pwd = this.txt_Pwd.Text.Trim();
            //判断用户输入的内容是否为null
            var isUserName = string.IsNullOrEmpty(userName);
            var isPwd = string.IsNullOrEmpty(pwd);
            var sql = string.Format("select * from Users where Username='{0}' and Password='{1}'", userName, pwd);
            var dt = DbHelper.GetSelect(sql);
            if (dt.Rows.Count == 1)
            {
                MessageBox.Show("登录成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                StuInfoManagementSystem stu = new StuInfoManagementSystem();
                stu.Show();
                this.Hide();
            }
            else if (isUserName && isPwd)
            {
                MessageBox.Show("用户名和密码不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if(isUserName)
            {
                MessageBox.Show("用户名不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (isPwd)
            {
                MessageBox.Show("密码不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("用户名和密码不存在！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        //注册
        private void btn_Register_Click(object sender, EventArgs e)
        {
            //实例化注册窗体
            Register register = new Register();
            //打开注册窗体
            register.Show();
            //隐藏当前窗体
            this.Hide();
        }

        //在输入完密码之后敲击回车键即可实现登录
        private void txt_Pwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btn_Login_Click(sender,e);
            }
        }
        //在用户名处敲击回车键实现登录效果
        private void txt_UserName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btn_Login_Click(sender,e);
            }
        }
        //关闭系统
        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //找回密码
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel1.LinkVisited = true;
            Process.Start("IExplore", "http://www.baidu.com");
        }
    }
}
